package com.linkelee.producer.configuration;


import com.linkelee.MqProducerPublisher;
import com.linkelee.properties.RpcMqConsumerProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnSingleCandidate(AmqpTemplate.class)
@EnableConfigurationProperties(RpcMqConsumerProperties.class)
@AutoConfigureAfter(RabbitAutoConfiguration.class)
@Slf4j
public class MqProducerAutoConfiguration {

    @Autowired
    private AmqpTemplate amqpTemplate;

    @Bean
    public MqProducerPublisher mqProducerPublisher() {
        return MqProducerPublisher.builder()
                .amqpTemplate(amqpTemplate).build();
    }

}
